#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e4+10;
const int maxm=80;
const int base=131;
typedef int LL;
typedef unsigned long long ull;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn][maxm];
ull calr[maxn][maxm],calc[maxn][maxm],p[maxn],a[maxn];
LL d[maxn],tot=0;
inline LL kmppre(int len){
    fill(d,d+len+1,0);
    int i=1;int j=0;
    while(i<len){
        if(a[i]==a[j]){
            d[i++]=++j;
        }else{
            if(j) j=d[j-1];
            else i++;
        }
    }
    tot=0;
    return len-d[len-1];
}
inline LL solver(LL x1,LL y1,LL x2,LL y2){
    for(int i=x1;i<=x2;i++) a[tot++]=calr[i][y2]-calr[i][y1-1]*p[y2-y1+1];
    return kmppre(x2-x1+1);
}
inline LL solvec(LL x1,LL y1,LL x2,LL y2){
    for(int i=y1;i<=y2;i++) a[tot++]=calc[x2][i]-calc[x1-1][i]*p[x2-x1+1];
    return kmppre(y2-y1+1);
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) cin>>str[i][j];
    }
    p[0]=1;
    for(int i=1;i<=n;i++){
        p[i]=p[i-1]*base;
        for(int j=1;j<=m;j++) calr[i][j]=calr[i][j-1]*base+(str[i][j]-'A');
    }
    for(int j=1;j<=m;j++){
        for(int i=1;i<=n;i++) calc[i][j]=calc[i-1][j]*base+(str[i][j]-'A');
    }
    cout<<solver(1,1,n,m)*solvec(1,1,n,m)<<endl;
   	return 0;
}
